using System;
using UnityEngine;

[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
[ExecuteInEditMode]
public class PlaneRoundSpotObject : MonoBehaviour
{
	public Color color
	{
		get
		{
			return this.innerColor;
		}
		set
		{
			if (this.color == value)
			{
				return;
			}
			this.innerColor = value;
			this.outerColor = value;
			this.BuildMesh();
		}
	}

	public Color colorOuterBlur
	{
		get
		{
			return this.innerColor;
		}
		set
		{
			if (this.color == value)
			{
				return;
			}
			this.innerColor = value;
			this.outerColor = value;
			this.outerColor.a = 0f;
			this.BuildMesh();
		}
	}

	private void Start()
	{
		this.BuildMesh();
	}

	private void Update()
	{
	}

	public void BuildMesh()
	{
		MeshFilter component = base.gameObject.GetComponent<MeshFilter>();
		Mesh mesh = new Mesh();
		mesh.vertices = this.BuildVertices();
		mesh.uv = this.BuildUvs();
		mesh.triangles = this.BuildTriangles();
		mesh.colors = this.BuildColors();
		mesh.RecalculateBounds();
		mesh.RecalculateNormals();
		component.mesh = mesh;
		Mesh sharedMesh = component.sharedMesh;
		sharedMesh.bounds = new Bounds
		{
			center = Vector3.zero,
			size = Vector3.one * this.outerRadius
		};
	}

	private Vector3[] BuildVertices()
	{
		Vector3[] array;
		if (this.innerRadius > 0f)
		{
			array = new Vector3[this.divideCount * 2];
			Vector3 zero = Vector3.zero;
			for (int i = 0; i < this.divideCount; i++)
			{
				zero.x = Mathf.Sin(6.28318548f / (float)this.divideCount * ((float)i + 0.5f));
				zero.y = Mathf.Cos(6.28318548f / (float)this.divideCount * ((float)i + 0.5f));
				array[i * 2] = zero * this.innerRadius;
				array[i * 2 + 1] = zero * this.outerRadius;
			}
		}
		else
		{
			array = new Vector3[this.divideCount + 1];
			Vector3 zero2 = Vector3.zero;
			for (int j = 0; j < this.divideCount; j++)
			{
				zero2.x = Mathf.Sin(6.28318548f / (float)this.divideCount * ((float)j + 0.5f));
				zero2.y = Mathf.Cos(6.28318548f / (float)this.divideCount * ((float)j + 0.5f));
				array[j] = zero2 * this.outerRadius;
			}
			array[this.divideCount] = Vector3.zero;
		}
		return array;
	}

	private Vector2[] BuildUvs()
	{
		Vector2[] array;
		if (this.innerRadius > 0f)
		{
			array = new Vector2[this.divideCount * 2];
		}
		else
		{
			array = new Vector2[this.divideCount + 1];
		}
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = Vector2.zero;
		}
		return array;
	}

	private int[] BuildTriangles()
	{
		int[] array;
		if (this.innerRadius > 0f)
		{
			array = new int[this.divideCount * 6];
			for (int i = 0; i < this.divideCount; i++)
			{
				array[i * 6] = i * 2;
				array[i * 6 + 1] = i * 2 + 1;
				array[i * 6 + 2] = ((i >= this.divideCount - 1) ? 1 : (i * 2 + 3));
				array[i * 6 + 3] = i * 2;
				array[i * 6 + 4] = ((i >= this.divideCount - 1) ? 1 : (i * 2 + 3));
				array[i * 6 + 5] = ((i >= this.divideCount - 1) ? 0 : (i * 2 + 2));
			}
		}
		else
		{
			array = new int[this.divideCount * 3];
			for (int j = 0; j < this.divideCount; j++)
			{
				array[j * 3] = this.divideCount;
				array[j * 3 + 1] = j;
				array[j * 3 + 2] = ((j >= this.divideCount - 1) ? 0 : (j + 1));
			}
		}
		return array;
	}

	private Color[] BuildColors()
	{
		Color[] array;
		if (this.innerRadius > 0f)
		{
			array = new Color[this.divideCount * 2];
			for (int i = 0; i < this.divideCount; i++)
			{
				array[i * 2] = this.innerColor;
				array[i * 2 + 1] = this.outerColor;
			}
		}
		else
		{
			array = new Color[this.divideCount + 1];
			for (int j = 0; j < this.divideCount; j++)
			{
				array[j] = this.outerColor;
			}
			array[this.divideCount] = this.innerColor;
		}
		return array;
	}

	public int divideCount = 36;

	public float innerRadius;

	public float outerRadius = 1f;

	public Color innerColor = Color.white;

	public Color outerColor = Color.black;
}
